package com.jservice.api.service.smk;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jservice.api.MsgCode;
import com.jservice.api.dto.Request;
import com.jservice.api.dto.Response;
import com.jservice.api.dto.ResponseHeader;
import com.jservice.api.service.BaseService;
import com.jservice.api.service.IService;
import com.jservice.api.smkAppUser.AppUserKit;
import com.jservice.model.SmkAppUser;
import com.jservice.model.SmkSms;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Smk0016 - 读取消息列表
 *
 * @Author cwledit
 * @DATE 2017/6/16.
 */
@Service("smk0016")
public class Smk0016 extends BaseService implements IService{

    @Override
    public Response excute(Request request, Response response, ResponseHeader header, String method) throws Exception {
        SmkAppUser smkAppUser = AppUserKit.getCurrent(request);
        if (smkAppUser == null){
            return renderFAIL(MsgCode.Code_1007,response,header);
        }
        Map paramMap = request.getData();
        Integer display_no = paramsIntegerFilter(paramMap.get("display_no"));
        Integer current_page_no = paramsIntegerFilter(paramMap.get("current_page_no"));
        String account = smkAppUser.getIdCard();
        if (display_no == null){
            display_no = 10;
        }
        if (current_page_no == null){
            current_page_no = 1;
        }
        String sqlSelect = "select *";
        String sql = "from "+ SmkSms.TABLE_NAME+" where account = ? order by create_date desc" ;
        Page page = Db.paginate(current_page_no,display_no,sqlSelect,sql,account);
        return renderSUC(page,response,header);

    }
}
